<template>
  <div>
    <svg-icon
      v-if="!isFull"
      class="myicon"
      icon-class="fullscreen"
      @click="handleChange"
    />
    <svg-icon
      v-else
      class="myicon"
      icon-class="exit-fullscreen"
      @click="handleChange"
    />
  </div>
</template>

<script>
// 必须指定版本号为5.0.1
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      // 是否是全屏
      isFull: false
    }
  },
  methods: {
    handleChange() {
      // 1. 判断当前运行的浏览器是否支持全屏操作
      if (!ScreenFull.isEnabled) {
        this.$message.warning('当前浏览器不支持全屏操作, 请更换浏览器~')
        return
      }

      // 2. 实现全屏和非全屏切换
      ScreenFull.toggle()
      this.isFull = !this.isFull
    }
  }
}
</script>

<style lang="scss" scoped>
.myicon{
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
